public class HashBuck {
    static class Node{
        public int key;
        public int val;
        public  Node next;

        public Node(int key, int val) {
            this.key = key;
            this.val = val;
        }
    }
    public Node[] array = new Node[10];
    public int usedSize;
    public static final double  LOAD_FACTOR = 0.75;

    //插入操作
    public void push(int key,int val) {
        //找到位置
        int index = key % array.length;
        Node node = new Node(key,val);
        //开始遍历数组
        Node cur = array[index];
        while (cur != null) {
            if (cur.key == key) {
                //更新val
                cur.val = val;
                return;
            }
            //头插
            node.next = array[index];
            array[index] = node;
            usedSize++;
            if (doLoadFactor() >= 0.75) {
                //重新哈希

            }

        }
    }

    private void reSize(){
        Node[] newArray = new Node[array.length*2];
        //处理重新哈希
        for (int i = 0;i<array.length;i++) {
            Node cur = array[i];
            while (cur != null) {
                int index = cur.key % newArray.length;
                //记录下来 之前的cur。next
                Node curNext = cur.next;
                //进行头插
                cur.next = newArray[index];
                newArray[index] = cur;
                cur = curNext;

            }
        }
        //把数据给原来的数组 array
        array = newArray;
    }



    private double doLoadFactor(){
        return usedSize*1.0/array.length;
    }

    //获取key值
    public int get(int key) {
        //1、找到位置
        int index = key % array.length;
        //遍历数组
        Node cur = array[index];
        while (cur != null) {
            if (cur.key == key) {
                return cur.val;
            }
            cur = cur.next;
        }
        return -1;
    }
}
